#ifndef __LOGGER_H__
#define __LOGGER_H__
#include<fstream>
#include"message.h"
/* 单例模式 */
class Logger
{
private:
    Logger();
    bool m_logToTerminal;
    bool m_logToLogFile;
    std::fstream m_logFile;
    LOG_LEVEL m_level;
public:
    static Logger* GetInstance();
    void SetLogToTerminal(bool logToTerminal);
    bool GetLogToTerminal() const;
    void SetLogToLogFile(bool logToLogFile);
    bool GetLogToLogFile() const;
    void SetLogFile(const std::string& logFileName = "dsf.log");
    void OffLogFile();
    void SetLogLevel(LOG_LEVEL level);
    LOG_LEVEL GetLogLevel() const;
    /* 如何与Message类组合？类和类之间的关系 */
    void operator+=(const Message& msg);
};
#endif


#define LOG(level) \
    if(level >= Logger::GetInstance()->GetLogLevel()) \
        *Logger::GetInstance() += \
            Message(level, __FILE__, __FUNCTION__, __LINE__)

#define LOG_INFO LOG(INFO)
#define LOG_ERROR LOG(ERROR)
#define LOG_DEBUG LOG(DEBUG)
/* fatal需要exit(-1);
 * 在logger.cc的+=运算符函数中查找有无FATAL，有则exit
 */
#define LOG_FATAL LOG(FATAL)


/*
int main()
{
    LOG_INFO << "hello world";  --> 等价于：下面的语句

    if(INFO >= Logger::GetInstance()->GetLogLevel())
        *Logger::GetInstance() += 
            Message(INFO, __FILE__, __FUNCTION__, __LINE__) << "hello world";
    Message 的 << 已重载，hello world会与Message拼合在一起，交付给Logger的+=运算符
}
*/